package com.xindaoapp.henghua.protocol;

import java.util.List;

import com.loopj.android.http.util.RequestQueue;
import com.loopj.android.http.util.Response.ErrorListener;
import com.loopj.android.http.util.Response.Listener;
import com.xindaoapp.henghua.entry.ArriveDataInfo;
import com.xindaoapp.henghua.entry.PropertyInfo;
import com.xindaoapp.henghua.entry.PropertyWithLabelDataInfo;
import com.xindaoapp.henghua.entry.ScandataInfo;
import com.xindaoapp.henghua.entry.SuperVisionInfo;
import com.xindaoapp.henghua.entry.TagsInfo;
import com.xindaoapp.henghua.entry.TransportDataInfo;
import com.xindaoapp.henghua.entry.UserInfo;
import com.xindaoapp.henghua.protocol.model.ArriveDataRequest;
import com.xindaoapp.henghua.protocol.model.LoginRequest;
import com.xindaoapp.henghua.protocol.model.PropertyRequest;
import com.xindaoapp.henghua.protocol.model.PropertyWithLabelDataRequest;
import com.xindaoapp.henghua.protocol.model.ScanDataRequest;
import com.xindaoapp.henghua.protocol.model.SuperVisionRequest;
import com.xindaoapp.henghua.protocol.model.TagsRequest;
import com.xindaoapp.henghua.protocol.model.TransportDataRequest;

public class MoccaApiImpl implements MoccaApi {
	private final RequestQueue mRequestQueue = new RequestQueue();

	@Override
	public void getPropertyDatas(String version, String projectId, Listener<PropertyInfo> listener,
			ErrorListener errorListener) {
		PropertyRequest request = new PropertyRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETPROPERTYDATS);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

	public String getAbsoluteUrl(String url) {
		return BASEURL + url;
	}

	@Override
	public void login(String packageName, String versionName, String giipVersion, String udid,
			Listener<UserInfo> listener, ErrorListener errorListener) {
		LoginRequest loginRequest = new LoginRequest(BASEURL, listener, errorListener);
		loginRequest.addParams(PARAM_ACTION, LOGINURI);
		loginRequest.addParams("udid", udid);
		loginRequest.addHeader("giipVersion", giipVersion);
		loginRequest.addHeader("udid", udid);
		loginRequest.addHeader("appVersion", versionName);
		loginRequest.addHeader("appName", packageName);
		mRequestQueue.add(loginRequest);
	}

	@Override
	public void getPropertyWithLabelDatas(String version, String projectId,
			Listener<List<PropertyWithLabelDataInfo>> listener, ErrorListener errorListener) {
		PropertyWithLabelDataRequest request = new PropertyWithLabelDataRequest(BASEURL, listener,
				errorListener);
		request.addParams(PARAM_ACTION, GETPROPERTYWITHLABELDATAS);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

	@Override
	public void getTags(String currentTime, Listener<List<TagsInfo>> listener, ErrorListener errorListener) {
		TagsRequest request = new TagsRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETTAGS);
		request.addParams(PARAM_CURRENTTIME, currentTime);
		mRequestQueue.add(request);
	}

	@Override
	public void getScanDatas(String version, String projectId, Listener<List<ScandataInfo>> listener,
			ErrorListener errorListener) {
		// TODO Auto-generated method stub
		ScanDataRequest request = new ScanDataRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETSCANDATAS);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

	@Override
	public void upSuperVisionDatas(String contentJson, Listener<Boolean> listener, ErrorListener errorListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getSuperVision(String version, String projectId, Listener<List<SuperVisionInfo>> listener,
			ErrorListener errorListener) {
		// TODO Auto-generated method stub
		SuperVisionRequest request = new SuperVisionRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETSUPERVISION);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

	@Override
	public void upArriveDatas(String contentJson, Listener<Boolean> listener, ErrorListener errorListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getArriveDatas(String version, String projectId, Listener<ArriveDataInfo> listener,
			ErrorListener errorListener) {
		// TODO Auto-generated method stub
		ArriveDataRequest request = new ArriveDataRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETARRIVEDATAS);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

	@Override
	public void upTransportDatas(String contentJson, Listener<Boolean> listener, ErrorListener errorListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void gettransportDatas(String version, String projectId,
			Listener<List<TransportDataInfo>> listener, ErrorListener errorListener) {
		TransportDataRequest request = new TransportDataRequest(BASEURL, listener, errorListener);
		request.addParams(PARAM_ACTION, GETTRANSPORTDATAS);
		request.addParams(PARAM_CURRENTTIME, version);
		request.addParams(PARAM_PROJECTID, projectId);
		mRequestQueue.add(request);
	}

}
